﻿namespace KinonekoSoftware.Studio.Pages.Others.Wiki
{
    public sealed class GlossaryGalleryViewModel : RepositoryGalleryItem
    {
        private readonly ConceptSystem _Engine;


        private int _version;
        
        public GlossaryGalleryViewModel()
        {
            _Engine    = Platform.GetEngine<ConceptSystem>();
            Glossaries = new ObservableCollection<Concept>();
        }

        private void Initialize()
        {
            Glossaries.AddMany(_Engine.Get(), true);
            _version = _Engine.Version;
        }

        protected override void OnStart()
        {
            Initialize();
            base.OnStart();
        }

        protected override void OnReceive(PageContext context)
        {
            if (_version != _Engine.Version)
            {
                Initialize();
            }
            
            base.OnReceive(context);
        }


        public ObservableCollection<Concept> Glossaries { get; }
    }
}